//
//  HPOtherView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/4.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "HPOtherView.h"

@implementation HPOtherView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    self.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    self.layer.cornerRadius = 5;
    _cellView = [[HPLTCellView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    _cellView.tag = 20;
    _cellView.hidden = YES;
    [self addSubview:_cellView];
    [_cellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    [self addSubview:self.noDataLabel];
    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
}
- (void)updateView{
    NSLog(@"最新作业 %@",_dataArray);
//    if (_dataArray.count == 0) {
////        for (int i = 0; i<4; i++) {
////            HPLTCellView *cell = (HPLTCellView *)[self viewWithTag:20+i];
////            cell.hidden = YES;
////        }
//        return;
//    }
////    for (int i = 0; i<_dataArray.count; i++) {
//        _noDataLabel.hidden = YES;
//        TheNewWorkListModel *model = _dataArray[0];
//        _cellView.hidden = NO;
//        _cellView.index = 0;
//        _cellView.userInteractionEnabled = YES;
//        _cellView.titleLabel.attributedText =  [[NSMutableAttributedString alloc] initWithString:model.className attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14],NSForegroundColorAttributeName: TITLECOLOR}];
//    if (model.teacherName.length >0) {
//        _cellView.teacherLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.teacherName attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
//    }
//
//    if (model.attendTime.length > 0) {
//        _cellView.timeLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.attendTime attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
//    }
//
//        NSString *str = [NSString stringWithFormat:@"应交：%@人 实交：%@人  ",model.classStudents,model.submitStudents];
//
//        NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:str];
//        //目的是想改变 ‘/’前面的字体的属性，所以找到目标的range
//        NSRange range1 = [str rangeOfString:@"实交："];
//        NSRange range2;
//        NSRange pointRange;
//        range2 = [str rangeOfString:@"人  "];
//        pointRange = NSMakeRange(range1.location+3, range2.location-range1.location-3);
//        [attribut addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:pointRange];
//        //赋值
//        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//        dic[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//        [attribut addAttributes:dic range:pointRange];
//        _cellView.otherLabel.attributedText = attribut;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goZuoYeView:)];
//        [_cellView addGestureRecognizer:tap];
////    }
    
    
    if (_dataArray.count <=1) {
        //        for (int i = 0; i<4; i++) {
        //            HPLTCellView *cell = (HPLTCellView *)[self viewWithTag:20+i];
        //            cell.hidden = YES;
        //        }
        return;
    }
    //    for (int i = 0; i<_dataArray.count; i++) {
    _noDataLabel.hidden = YES;
    TheNewWorkListModel *model = _dataArray[0];
    _cellView.hidden = NO;
    _cellView.index = 0;
    _cellView.userInteractionEnabled = YES;
    _cellView.titleLabel.attributedText =  [[NSMutableAttributedString alloc] initWithString:model.className attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14],NSForegroundColorAttributeName: TITLECOLOR}];
    _cellView.teacherLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.paperName attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
    _cellView.timeLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.upLoadDate attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
    NSString *str = [NSString stringWithFormat:@"应交：%@人 实交：%@人  ",model.classStudents,model.submitStudents];
    
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:str];
    //目的是想改变 ‘/’前面的字体的属性，所以找到目标的range
    NSRange range1 = [str rangeOfString:@"实交："];
    NSRange range2;
    NSRange pointRange;
    range2 = [str rangeOfString:@"人  "];
    pointRange = NSMakeRange(range1.location+3, range2.location-range1.location-3);
    [attribut addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:pointRange];
    //赋值
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [attribut addAttributes:dic range:pointRange];
    _cellView.otherLabel.attributedText = attribut;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goZuoYeView:)];
    [_cellView addGestureRecognizer:tap];
    
}
- (void)goZuoYeView:(UITapGestureRecognizer *)gesture{
    HPLTCellView *cellView = (HPLTCellView *)gesture.view;
    TheNewWorkListModel *model = _dataArray[cellView.index];
    self.goZuoYeBlock(model);
}
- (UILabel *)noDataLabel{
    if (!_noDataLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"当前数据为空";
        label.textAlignment = 1;
        _noDataLabel = label;
    }
    return _noDataLabel;
}
//- (UILabel *)firstLabel{
//    if (!_firstLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"李文静 逐字稿 3-16 17:25";
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:32/255.0 green:176/255.0 blue:151/255.0 alpha:1.0]}];
//        label.attributedText = string;
//        _firstLabel = label;
//    }
//    return _firstLabel;
//}
//- (UILabel *)secondLabel{
//    if (!_secondLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"张艺鑫 过课 新概念67 3-16 17:25";
//        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
//        label.attributedText = string;
//        _secondLabel = label;
//    }
//    return _secondLabel;
//}
//- (void)updateView{
//    if (_dataArray.count>0) {
//        _noDataLabel.hidden = YES;
//    }
//    for (int i = 0; i<_dataArray.count; i++) {
//        UILabel *first = (UILabel *)[self viewWithTag:i+20];
//        UILabel *second = (UILabel *)[self viewWithTag:i+30];
//        first.hidden = NO;
//        second.hidden = NO;
//        if (i%2 == 0) {
//            HomeShiXunModel *model = _dataArray[i];
//            NSString *firstText = [NSString stringWithFormat:@"%@ %@ %@",model.name,model.trainName,model.createDate];
//            first.text = firstText;
//        }else{
//            HomeShiXunModel *model = _dataArray[i];
//            NSString *firstText = [NSString stringWithFormat:@"%@ %@ %@%@",model.name,model.trainName,model.textbook,model.createDate];
//            second.text = firstText;
//        }
//        
//    }
//    
//}
@end
